from PyQt5 import QtWidgets, QtCore
from PyQt5.QtGui import QPalette,QColor
from mainw import MainW
# from single import SingleApplication
import json
import os
import sys
import logging
import myglobal
import logging
import config_json
import time
from logging.handlers import RotatingFileHandler


handlers=[RotatingFileHandler(filename="report.log", maxBytes=10*1024*1024, encoding='utf-8',backupCount=3),# logging.FileHandler(initpath+'/myapp.log'),
    logging.StreamHandler(sys.stdout)]
logging.basicConfig(level=logging.DEBUG,
                    format = '%(asctime)s - %(name)s - %(levelname)s -%(funcName)s - %(message)s',
                    handlers=handlers)
logging.info(["begin",time.perf_counter()])
def qingyun_style(a):
    # f=open("qss/lightblue.css", "r") 
    # f=open("qss/blacksoft.css", "r") 
    f=open(os.path.join(myglobal.initpath,"qss","blacksoft.css"),"r")#"flatgray.css"), "r") 
    _style = f.read()
    # print(_style)
    paletteColor=_style[20:20+7]
    # print(paletteColor)
    a.setPalette(QPalette(QColor(paletteColor)));
    a.setStyleSheet(_style);
def github_style(a):
    # with open("qss/ManjaroMix.qss", "r") as f:
    # with open("qss/Ubuntu.qss", "r") as f:
    # with open("qss/NeonButtons.qss", "r") as f:
    f=open(os.path.join(getpath.getpath(),"qss","MaterialDark.qss"), "r")
    # with open("qss/AMOLED.qss", "r") as f:
    # with open("qss/ConsoleStyle.qss", "r") as f:
    # f=open("qss/MacOS.qss", "r")
    # f=open("qss/ElegantDark.qss", "r")
    a.setStyleSheet(f.read());
def main_single():
    pass
    # a=SingleApplication(sys.argv)
    # qingyun_style(a)
    # # github_style(a)
    # if a.is_running:
    #     print(dir(a.socket))
    #     a.socket.write(json.dumps(sys.argv).encode())
    #     s.socket.flush()
    #     a.quit()
    # else:
    #     # apply_stylesheet(a, theme='dark_cyan.xml')
    #     a.setQuitOnLastWindowClosed(True)
    #     m = MainW()
    #     m.show()
    #     sys.exit(a.exec_())    
def main():
    a=QtWidgets.QApplication(sys.argv)
    # qingyun_style(a)
    a.setQuitOnLastWindowClosed(True)
    m = MainW()
    m.show()
    sys.exit(a.exec_())
if __name__ == "__main__":
    main()
    # testlink()
